package com.inetools.gwetons.client.logging;

import com.inetools.gwetons.shared.logging.LogUtil;
import com.inetools.gwetons.shared.logging.LogUtilAdapterTemplate;

public abstract class JsniLogUtilAdapterTemplate extends LogUtilAdapterTemplate {
	/* Synchronization over jsniLogUtilFactoryInterface member field is not necessary since 
	 * JavaScript is single thread environment.
	 */
	private JsniLogUtilFactoryInterface jsniLogUtilFactoryInterface;
		protected JsniLogUtilFactoryInterface getJsniLogUtilFactoryInterface() {
			return jsniLogUtilFactoryInterface;
		}
		protected void setJsniLogUtilFactoryInterface(
				JsniLogUtilFactoryInterface jsniLogUtilFactoryInterface) {
			
			this.jsniLogUtilFactoryInterface = jsniLogUtilFactoryInterface;
			setLogUtilFactoryIntf( jsniLogUtilFactoryInterface);
		}
	
	private JsniLogUtil jsniLogUtil;
		protected JsniLogUtil getJsniLogUtil() {
			if ( jsniLogUtil == null) {
				setJsniLogUtil( 
						JsniLogUtilFactory.getJsniLogUtil( 
								null, 
								getLogUtil(), 
								getNameForLogging(), 
								getJsniLogUtilFactoryInterface()
								)
						);
			}
			return jsniLogUtil;
		}
		protected void setJsniLogUtil( JsniLogUtil jsniLogUtil) {
			this.jsniLogUtil = jsniLogUtil;
		}
	
	@Override
	protected void setLogUtil( LogUtil logUtil) {
		super.setLogUtil( logUtil);
		setJsniLogUtil( null);
	}
}
